<?php

namespace Modules\Admin\app\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\Admin\app\Http\Requests\LoginRequest;
use Modules\Admin\services\CaptchaService;
use Modules\Admin\services\LoginService;

class LoginController extends BaseController
{
    /**
     * 获取admin登录的验证码
     */
    public function captcha()
    {
        return CaptchaService::getInstance()->getInlineImageAndCode();
    }

    /**
     * Undocumented function
     *
     * @return 
     */
    public function login(LoginRequest $request, LoginService $service)
    {
        $validated = $request->validated();
        
        return $this->success([
            'token' => $service->login($validated),
        ]);
    }

    /**
     * 获取用户信息
     *
     * @return 
     */
    public function userinfo(Request $request)
    {
        $adminInfo = auth('admin_api')->user();
        return $this->success([
            'user' => $adminInfo,
        ], '获取成功');
    }
}
